﻿using Sidvall.Serialization;
using System;
using System.Globalization;
using System.Windows.Data;

namespace Sidvall.UI.Wpf.Converters
{
    public class MultiStringToBooleanConverter : IMultiValueConverter
    {
        #region Public Members

        #region Not

        private bool _Not = false;
        public bool Not
        {
            get
            {
                return _Not;
            }
            set
            {
                _Not = value;
            }
        }

        #endregion

        #region Convert

        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            return StringToBoolean(values);
        }

        #endregion
        #region ConvertBack

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        #endregion

        #endregion
        #region Private Members

        #region StringToBoolean

        private bool StringToBoolean(object[] values)
        {
            if (values == null)
                return false;
            if (values.Length != 2)
                return false;
            if (values[0].ToString(string.Empty).Equals(values[1].ToString(string.Empty), true, System.StringComparison.OrdinalIgnoreCase))
            {
                if (!this.Not)
                    return true;
                else
                    return false;
            }
            else
            {
                if (!this.Not)
                    return false;
                else
                    return true;
            }
        }

        #endregion

        #endregion
    }
}
